home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / LayerMgr / Re Hidden Applications < prev    next >
Text File  |  1993-02-15  |  10KB  |  292 lines

  1.  
  2.           Monday, February 15, 1993 10:40:57 AM
  3.           mac.programmer Item
  4.    From:          Michael Hecht,Michael_Hecht@mac.sas.com,Internet
  5.    Subject:       Re: Hidden Applications
  6.    To:            mac.programmer
  7. In article <1lhan6INNhuc@newsstand.cit.cornell.edu> Dave Irwin,
  8. dki1@cornell.edu writes:
  9. >For a program I'm working on I'd like to be able to launch an 
  10. >application and then "hide" it, in a manner similar to the way the OS 
  11. >hides an app when the user chooses "Hide..." from the application menu.  
  12. >Is there any way to tell the OS to hide an app, or to duplicate this 
  13. >effect?  (Note that the apps I'm launching won't have any ability to 
  14. >hide themselves.)
  15.  
  16. What you need is info on the undocumented "Layer Manager". Each
  17. application has a "layer" which is similar to a window. In fact, you can
  18. use the HideWindow and ShowWindow calls on a layer to do what you want.
  19. The layer's "visible" field tells you if the layer is showing or hidden.
  20.  
  21. Someone (noted below) previously posted some info they had uncovered on
  22. the Layer Manager. I've taken that info and expanded & corrected it. The
  23. C header file below should help you do what you want. This header file
  24. only describes the more interesting selectors.
  25.  
  26. The ones I left out do things like create a new layer, construct an
  27. update event for a layer, collect a layer's window's structure regions
  28. together, etc., etc.
  29.  
  30. I redefined the LayerRecord based on a WindowRecord, remapping the window
  31. fields to their counterparts in a layer.
  32.  
  33. I discovered that there seems to be a layer whose elements are not
  34. windows, but the layers of all running processes. I called this a
  35. metaLayer, and discovered that a layer with the goAwayFlag set indicates
  36. a metaLayer. Each process' layer has this metaLayer as a parent, and this
  37. metaLayer has another metaLayer as its parent (I don't know why). This
  38. metaLayer seems to be topmost, as its parent is NIL. I called this
  39. topmost layer the deskLayer, since it seems to describe the entire
  40. desktop.
  41.  
  42. I also found a neat routine that calls back an action proc for each
  43. window of each layer. I called this ForEachLayerWindowDo. I'm a bit hazy
  44. on the first three parameters--they seem to describe the bounds of the
  45. search. I think they're a starting layer, a starting window, and maybe a
  46. parent layer, but I'm not quite sure how they interact. It seems you're
  47. able to pass -1, 0, or an actual LayerPtr or WindowPtr for them. Let me
  48. know what you discover!
  49.  
  50. Anyway, here's the H file, plus a sample routine that uses
  51. ForEachLayerWindowDo to locate the layer belonging to a given PSN.
  52.  
  53. Good luck!
  54. --Michael
  55.  
  56. =======================================================================
  57. Michael P. Hecht                 | Internet:  Michael_Hecht@mac.sas.com
  58. SAS Institute Inc.; Cary, NC USA | AppleLink: SAS.HECHT
  59.  
  60.  
  61. ============begin LayerMgr.h=================
  62. #ifndef __LAYERMGR__
  63. #define __LAYERMGR__
  64.  
  65. #ifndef __PROCESSES__
  66. #include <Processes.h>
  67. #endif
  68.  
  69.  
  70. //Subject: UNofficial description of 2 Layer Manager calls
  71. //From: Hugues Marty, hugues@isoftfr.isoft.fr
  72. //Date: 28 Aug 92 08:11:24 GMT
  73. //
  74. //
  75. //
  76. //This post contains a header and an example of how to use some calls of
  77. //the UNDOCUMENTED (as long as I know) Layer Manager which comes along
  78. //with System 7.  Of course, this is NOT an official document, and is
  79. //here for information only. I don't have News access at the moment (I'm
  80. //sending this via e-mail), so please send mail me copies if you post
  81. //follow-ups.
  82. //
  83. //PS: it only describes 2 calls of the LayerDispatch trap (0xA829).
  84. //PPS: seems to work under 7.1 beta.
  85.  
  86. /* Part of the undocumented Layer Manager structures and calls
  87.  * Information found with the help of MacsBug under MacOS 7.0.
  88.  * Please note that using this information may make your mac
  89.  * explode (hey, this could be a subject for a QuickTime moovie !);
  90.  * so use at your own risks, this may break in the future,
  91.  * etc.. (usual disclaimeer).
  92.  * I only wish that Apple will document this manager in a very near
  93.  * future (let's dream...).
  94.  *
  95.  * What I found was that a layer is associated with each running
  96.  * applications (if it has a user-interface), which groups all
  97.  * windows of that application. This is how you can hide an application
  98.  * (remember 'applications' menu under system 7) and get the list of
  99.  * other applications windows. Have fun.
  100.  *
  101.  * PS : If you have more information on the Layer Manager, please
  102.  * let me know! You can join me at hugues@isoft.fr
  103.  */
  104.  
  105. //    11FEB93        Added descriptions of several more selectors;
  106. //                other minor improvements.
  107. //                Michael Hecht, Michael_Hecht@mac.sas.com
  108.  
  109. // The _LayerDispatch trap
  110. #define _LayerDispatch    0xA829
  111.  
  112. // LayerRecord is similar to a WindowRecord.
  113. typedef WindowPtr LayerPtr;
  114.  
  115. // This records some information on the process which owns
  116. // the layer... Most of it is not clear (there are pointers
  117. // to other LayerRecords, to a heap zone, etc. in the unknown
  118. // parts)
  119. typedef struct {
  120.     long                unknown1;
  121.     OSType                signature;            // The process sig.
  122.     OSType                creator;            // The process creator
  123.     char                unknown2[24];
  124.     ProcessSerialNumber    layerPSN;            // The process PSN
  125.     char                unknown3[40];
  126.     Handle                moreLayerInfo;        // This handle is 212 bytes sized.
  127. } LayerInfo, *LayerInfoPtr;
  128.  
  129. typedef struct {
  130.     GrafPort            port;                // txSize == 0xDEAD
  131.     short                windowKind;
  132.     Boolean                visible;            // the layer's visibility: HideWindow
  133.     Boolean                hilited;
  134.     Boolean                metaLayer;            // a layer of layers
  135.     Boolean                spareFlag;
  136.     RgnHandle            strucRgn;
  137.     RgnHandle            contRgn;
  138.     RgnHandle            updateRgn;
  139.     Handle                windowDefProc;
  140.     LayerPtr            parentLayer;        // layer of which this is a member
  141.     AuxWinHandle        auxWinHead;            // this layer's AuxWinHead
  142.     short                titleWidth;
  143.     AuxCtlHandle        auxCtlHead;            // this layer's AuxCtlHead
  144.     LayerPtr            nextLayer;            // next layer in the chain
  145.     WindowPtr            windowList;            // this layer's WindowList
  146.     LayerInfoPtr        layerInfo;            // this layer's add'l info: GetWRefCon
  147. } LayerRecord, *LayerPeek;
  148.  
  149.  
  150. typedef short    WindowActionCode;
  151. enum {
  152.     kNextWindow = 0,
  153.     kNextLayer = 700,
  154.     kBreak
  155. };
  156. typedef pascal WindowActionCode ( *LayerActionProcPtr )(
  157.     WindowPtr theWindow, LayerPtr theLayer, long refCon );
  158. #define kAllLayers ((LayerPtr)-1)
  159.  
  160. // Call the action proc for each window in each layer
  161. pascal WindowActionCode ForEachLayerWindowDo(
  162.     LayerPtr layer1, LayerPtr layer2, LayerPtr layer3,
  163.     LayerActionProcPtr layerAction, long refCon ) = { 0x70F8, _LayerDispatch
  164. };
  165.  
  166. // Return the window's layer
  167. pascal LayerPtr WindowLayer( WindowPtr theWindow ) = { 0x70F9,
  168. _LayerDispatch };
  169.  
  170. // Return the frontmost visible window in the given layer
  171. pascal WindowPtr LayerFrontVisibleWindow( LayerPtr theLayer )
  172.     = { 0x70FD, _LayerDispatch };
  173.  
  174. // Return the frontmost visible window on the desktop
  175. pascal WindowPtr DeskFrontVisibleWindow( void ) = { 0x70FE,
  176. _LayerDispatch };
  177.  
  178. // Return the desktop's layer (contains all other layers)
  179. pascal LayerPtr DeskLayer( void ) = { 0x70FF, _LayerDispatch };
  180.  
  181. // Return TRUE if theLayer is really a LayerPtr; return FALSE if it's a
  182. WindowPtr
  183. pascal Boolean IsLayer( LayerPtr theLayer ) = { 0x7002, _LayerDispatch };
  184.  
  185. // Return the current process' layer
  186. pascal LayerPtr CurrentLayer( void ) = { 0x7003, _LayerDispatch };
  187.  
  188. // Return the first window of this layer.
  189. pascal WindowPtr LayerFrontWindow( LayerPtr theLayer ) = { 0x7006,
  190. _LayerDispatch };
  191.  
  192. // All-layer version of FindWindow
  193. pascal short FindLayerWindow( Point where, WindowPtr *foundWindow )
  194.     = { 0x7007, _LayerDispatch };
  195.  
  196. #define LayerVisible(aLayer)    (((LayerPeek)aLayer)->visible)
  197.  
  198. #endif
  199. ============end LayerMgr.h=================
  200.  
  201. ============begin LayerTest.c=================
  202. #include "LayerMgr.h"
  203.  
  204.  
  205. // Set to TRUE if _LayerDispatch exists
  206. extern Boolean gLayersAvailable;
  207.  
  208. // Parameters to our LayerActionProc
  209. typedef struct {
  210.     ProcessSerialNumber    *findPSN;
  211.     LayerPtr            foundLayer;
  212. } FindLayerParmRec, *FindLayerParmPtr;
  213.  
  214.  
  215. // FindLayerProcess: a LayerActionProc that looks for a specific PSN
  216. static pascal WindowActionCode FindLayerProcess(
  217.     WindowPtr theWindow, LayerPtr theLayer, long refCon )
  218. {
  219.     WindowActionCode    code;
  220.     LayerInfoPtr        info;
  221.     FindLayerParmPtr    p;
  222.     Boolean                same;
  223.  
  224.  
  225.     /* Assume we'll be going to the next layer */
  226.     code = kNextLayer;
  227.  
  228.     /* If this window is really a layer, use it and go to the next "window"
  229. */
  230.     if( IsLayer( theWindow )) {
  231.         theLayer = theWindow;
  232.         code = kNextWindow;
  233.     }
  234.  
  235.     /* If we got a layer... */
  236.     if( theLayer ) {
  237.  
  238.         /* ...with some info */
  239.         info = ( LayerInfoPtr )GetWRefCon( theLayer );
  240.         if( info ) {
  241.  
  242.             /* See if the PSNs match */
  243.             p = ( FindLayerParmPtr )refCon;
  244.             SameProcess( &info->layerPSN, p->findPSN, &same );
  245.             if( same ) {
  246.  
  247.                 /* They do; remember the layer and break out */
  248.                 p->foundLayer = theLayer;
  249.                 code = kBreak;
  250.             }
  251.         }
  252.     }
  253.  
  254.     return code;
  255. }
  256.  
  257. /* ProcessLayer: find a process' layer by its PSN */
  258. LayerPtr ProcessLayer( ProcessSerialNumber *psn )
  259. {
  260.     FindLayerParmRec    p;
  261.  
  262.  
  263.     if( !gLayersAvailable )
  264.         return 0;
  265.  
  266.     p.findPSN = psn;
  267.     p.foundLayer = 0;
  268.  
  269.     ForEachLayerWindowDo( DeskLayer(), kAllLayers, 0, FindLayerProcess, (
  270. long )&p );
  271.     return p.foundLayer;
  272. }
  273. ============end LayerTest.c=================
  274.  
  275.  
  276. ------ Internet Message Header Follows ------
  277. Newsgroups: comp.sys.mac.programmer
  278. Path: uupsi!psinntp!rpi!gatech!concert!sas!mozart.unx.sas.com!studly.mac.sas.com!Michael_Hecht
  279. From: Michael Hecht <Michael_Hecht@mac.sas.com>
  280. Subject: Re: Hidden Applications
  281. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  282. Message-ID: <C2FzKG.Bu4@unx.sas.com>
  283. X-Useragent: Nuntius v1.1.1d17
  284. Date: Sun, 14 Feb 1993 14:14:40 GMT
  285. X-Xxdate: Sun, 14 Feb 93 13:56:00 GMT
  286. X-Xxmessage-Id: <A7A3B9A0FA05050A@studly.mac.sas.com>
  287. References: <1lhan6INNhuc@newsstand.cit.cornell.edu>
  288. Nntp-Posting-Host: studly.mac.sas.com
  289. Organization: SAS Institute Inc.
  290. Lines: 267
  291.  
  292.